#ifndef FILEMANAGER_H
#define FILEMANAGER_H

//Todo : coding.....

#include <QTcpServer>
#include <QMap>
#include <QMutex>
#include <QThread>
#include <QHostAddress>

#include "FileKey.h"

class FileReceiver;
class FileSender;

class FileManager : public /*QObject*/QTcpServer
{
	Q_OBJECT
	public:
		FileManager();
		~FileManager();
		bool Initialize(int capacity = 5);

	protected:
		void incomingConnection(int socketDescriptor);

	private:
		bool DeleteTask(FileKey key);

	private slots:
		void AddSendTask(QHostAddress addr, QString filePath);
		void OnStart(FileKey key, long long size);
		void OnError(FileKey key, QString errorStr);
		void OnProcessing(FileKey key, int nbytes);
		void OnComplete(FileKey key);

	private:
		QMap<FileKey, FileReceiver*> _recvTask;
		QMap<FileKey, FileSender*> _sendTask;
		int _capacity;
		QMutex _mutex;
		QThread *_thread;

	signals:
		void sigNotice(QString str);
		void sigOnProcessing(FileKey key, int size);
		void sigMakeProgressBar(FileKey key, long long size);
		void sigDestroyProgressBar(FileKey key);
		void sigEnableProgressBarButton(FileKey key);
};

#endif // FILEMANAGER_H
